package com.wt.springboot.service.impl;

import com.wt.springboot.bean.Department;
import com.wt.springboot.mapper.DepartmentMapper;
import com.wt.springboot.service.DepartmentService;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.beans.factory.annotation.Qualifier;
import org.springframework.cache.Cache;
import org.springframework.cache.annotation.Cacheable;
import org.springframework.data.redis.cache.RedisCacheManager;
import org.springframework.stereotype.Service;

/**
 * Created with IDEA
 * Describe:
 * Author:TianJi
 * Date:2018/11/16
 * Time:20:20
 */
@Service
public class DepartmentServiceImpl implements DepartmentService {
    @Autowired
    private DepartmentMapper departmentMapper;

    @Qualifier("deptCacheManager")
    @Autowired
    private RedisCacheManager deptCacheManager;

    /* @Cacheable(value = "dept",cacheManager = "deptCacheManager")
    @Override
    public Department getDeptById(Integer id) {
        return departmentMapper.getDeptById(id);
    }*/
    @Override
    public Department getDeptById(Integer id) {
        Department department = departmentMapper.getDeptById(id);
        Cache dept = deptCacheManager.getCache("dept");
        dept.put("dept:1",department);
        return department;
    }
}
